package com.chy.blog_web.core.el;

import java.util.Iterator;
import java.util.Map;

public class ElUtil {

	private static String[] dangerousCharacters = {"getClass", "forName", "getMethods", "invoke", "getClassLoader", "loadClass", "newInstance", "exec", "inputStream", "java.lang.Runtime", "javax.naming.InitialContext", "ldap", "ldXp"};


	/**
	 * 校验表达式格式‘#{xxxxx}’
	 * @param str
	 * @return
	 */
	public static Boolean getMatcher(String str) {
		if (str != null && !"".equals(str.trim())) {
			String regex = "(#\\{)[^#]+(\\})";
			return str.matches(regex);
		}
		return false;
	}

	/**
	 * 危险字符校验
	 *
	 * @param paramValue
	 * @return
	 */
	public static boolean isDangerousCharacters(String paramValue) {
		if (paramValue != null && paramValue.length() > 50) {
			System.err.println("表达式[" + paramValue + "]长度过长疑似危险字符");
			return true;
		}

		for (String dc : dangerousCharacters) {
			if (paramValue.indexOf(dc) > -1) {
				System.err.println("表达式[" + paramValue + "]中存在危险字符");
				return true;
			}
		}
		return false;
	}
}
